<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="jquery.min.js"></script>
</head>

<body>
    <script>
        let p1 = new Promise((resolve, reject) => {

            $.ajax({
                url: '/data.txt',
                dataType: 'json',
                success: (success) => {
                    resolve(success)
                },
                error: (err) => {
                    reject(err)
                }
            })

            // (resolve(success)) || (reject(err))
        })
        
        p2 = new Promise((resolve, reject) => {
            $.ajax({
                url: '/arr.json',
                dataType: 'json',
                success(success) {
                    resolve(success)
                },
                error(err) {
                    reject(err)
                }
            })
        })

        
        // p1.then((success) => {
        //     alert('请求成功')
        //     success.forEach(element => {
        //         console.log(element);
        //     });
        // }, err => {
        //     alert('请求错误')
        // })
        

        // p2.then((success) => {
        //     alert('请求成功')
        //     success.forEach(item => {
        //         console.log(item);
        //     })
        // }, (err) => {
        //     alert('请求错误')
        // })

        Promise.all([
            p1, p2
        ]).then(success => {
            let [res1, res2] = success;
            console.log(res1);
            console.log(res2);
            
        }, err => {
            console.log('至少有一个失败了');
            
        })

        p3 = new Promise((resolve, reject) => {
            $.ajax({
                url:'arr1.txt',
                dataType: 'json',
                success:(success) => {
                    resolve(success)
                },
                error: (error) => {
                    reject(error)
                }
            })
        })

        p3.then( success => {
            // success.forEach(item => {
            //     console.log(item);
            // })
            console.log(success);
            
        }, error => {
            console.log(error);
            
        })
    </script>
</body>

</html>